home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / network / ncsasock / a_namesr.h < prev    next >
Text File  |  1996-07-05  |  8KB  |  236 lines

  1. /*
  2.  * Copyright (c) 1983, 1989 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  *
  19.  *    @(#)nameser.h    5.24 (Berkeley) 6/1/90
  20.  */
  21.  
  22. /*
  23.  * Define constants based on rfc883
  24.  */
  25. #define PACKETSZ    512        /* maximum packet size */
  26. #define MAXDNAME    256        /* maximum domain name */
  27. #define MAXCDNAME    255        /* maximum compressed domain name */
  28. #define MAXLABEL    63        /* maximum length of domain label */
  29.     /* Number of bytes of fixed size data in query structure */
  30. #define QFIXEDSZ    4
  31.     /* number of bytes of fixed size data in resource record */
  32. #define RRFIXEDSZ    10
  33.  
  34. /*
  35.  * Internet nameserver port number
  36.  */
  37. #define NAMESERVER_PORT    53
  38.  
  39. /*
  40.  * Currently defined opcodes
  41.  */
  42. #define QUERY        0x0        /* standard query */
  43. #define IQUERY        0x1        /* inverse query */
  44. #define STATUS        0x2        /* nameserver status query */
  45. /*#define xxx        0x3        /* 0x3 reserved */
  46.     /* non standard */
  47. #define UPDATEA        0x9        /* add resource record */
  48. #define UPDATED        0xa        /* delete a specific resource record */
  49. #define UPDATEDA    0xb        /* delete all nemed resource record */
  50. #define UPDATEM        0xc        /* modify a specific resource record */
  51. #define UPDATEMA    0xd        /* modify all named resource record */
  52.  
  53. #define ZONEINIT    0xe        /* initial zone transfer */
  54. #define ZONEREF        0xf        /* incremental zone referesh */
  55.  
  56. /*
  57.  * Currently defined response codes
  58.  */
  59. #define NOERROR        0        /* no error */
  60. #define FORMERR        1        /* format error */
  61. #define SERVFAIL    2        /* server failure */
  62. #define NXDOMAIN    3        /* non existent domain */
  63. #define NOTIMP        4        /* not implemented */
  64. #define REFUSED        5        /* query refused */
  65.     /* non standard */
  66. #define NOCHANGE    0xf        /* update failed to change db */
  67.  
  68. /*
  69.  * Type values for resources and queries
  70.  */
  71. #define T_A        1        /* host address */
  72. #define T_NS        2        /* authoritative server */
  73. #define T_MD        3        /* mail destination */
  74. #define T_MF        4        /* mail forwarder */
  75. #define T_CNAME        5        /* connonical name */
  76. #define T_SOA        6        /* start of authority zone */
  77. #define T_MB        7        /* mailbox domain name */
  78. #define T_MG        8        /* mail group member */
  79. #define T_MR        9        /* mail rename name */
  80. #define T_NULL        10        /* null resource record */
  81. #define T_WKS        11        /* well known service */
  82. #define T_PTR        12        /* domain name pointer */
  83. #define T_HINFO        13        /* host information */
  84. #define T_MINFO        14        /* mailbox information */
  85. #define T_MX        15        /* mail routing information */
  86. #define T_TXT        16        /* text strings */
  87.     /* non standard */
  88. #define T_UINFO        100        /* user (finger) information */
  89. #define T_UID        101        /* user ID */
  90. #define T_GID        102        /* group ID */
  91. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  92.     /* Query type values which do not appear in resource records */
  93. #define T_AXFR        252        /* transfer zone of authority */
  94. #define T_MAILB        253        /* transfer mailbox records */
  95. #define T_MAILA        254        /* transfer mail agent records */
  96. #define T_ANY        255        /* wildcard match */
  97.  
  98. /*
  99.  * Values for class field
  100.  */
  101.  
  102. #define C_IN        1        /* the arpa internet */
  103. #define C_CHAOS        3        /* for chaos net at MIT */
  104. #define C_HS        4        /* for Hesiod name server at MIT */
  105.     /* Query class values which do not appear in resource records */
  106. #define C_ANY        255        /* wildcard match */
  107.  
  108. /*
  109.  * Status return codes for T_UNSPEC conversion routines
  110.  */
  111. #define CONV_SUCCESS 0
  112. #define CONV_OVERFLOW -1
  113. #define CONV_BADFMT -2
  114. #define CONV_BADCKSUM -3
  115. #define CONV_BADBUFLEN -4
  116.  
  117. #ifndef BYTE_ORDER
  118. #define    LITTLE_ENDIAN    1234    /* least-significant byte first (vax) */
  119. #define    BIG_ENDIAN    4321    /* most-significant byte first (IBM, net) */
  120. #define    PDP_ENDIAN    3412    /* LSB first in word, MSW first in long (pdp) */
  121.  
  122. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(MIPSEL) || defined(BIT_ZERO_ON_RIGHT)
  123. #define BYTE_ORDER    LITTLE_ENDIAN
  124.  
  125. #endif
  126.  
  127. #if defined(THINK_C) && !defined(mc68000)
  128. #define mc68000
  129. #endif
  130.  
  131. #if defined(sel) || defined(pyr) || defined(powerc) || defined(__powerc) || defined(__MWERKS__) || defined(mc68000) || defined(sparc) || defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || defined(MIPSEB) || defined (BIT_ZERO_ON_LEFT)
  132. #define BYTE_ORDER    BIG_ENDIAN
  133. #endif
  134. #endif /* BYTE_ORDER */
  135.  
  136. #ifndef BYTE_ORDER
  137.     /* you must determine what the correct bit order is for your compiler */
  138.     UNDEFINED_BIT_ORDER;
  139. #endif
  140. /*
  141.  * Structure for query header, the order of the fields is machine and
  142.  * compiler dependent, in our case, the bits within a byte are assignd 
  143.  * least significant first, while the order of transmition is most 
  144.  * significant first.  This requires a somewhat confusing rearrangement.
  145.  */
  146.  
  147. typedef struct {
  148.     u_short    id;        /* query identification number */
  149. #if BYTE_ORDER == BIG_ENDIAN
  150.             /* fields in third byte */
  151.     u_char    qr:1;        /* response flag */
  152.     u_char    opcode:4;    /* purpose of message */
  153.     u_char    aa:1;        /* authoritive answer */
  154.     u_char    tc:1;        /* truncated message */
  155.     u_char    rd:1;        /* recursion desired */
  156.             /* fields in fourth byte */
  157.     u_char    ra:1;        /* recursion available */
  158.     u_char    pr:1;        /* primary server required (non standard) */
  159.     u_char    unused:2;    /* unused bits */
  160.     u_char    rcode:4;    /* response code */
  161. #endif
  162. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  163.             /* fields in third byte */
  164.     u_char    rd:1;        /* recursion desired */
  165.     u_char    tc:1;        /* truncated message */
  166.     u_char    aa:1;        /* authoritive answer */
  167.     u_char    opcode:4;    /* purpose of message */
  168.     u_char    qr:1;        /* response flag */
  169.             /* fields in fourth byte */
  170.     u_char    rcode:4;    /* response code */
  171.     u_char    unused:2;    /* unused bits */
  172.     u_char    pr:1;        /* primary server required (non standard) */
  173.     u_char    ra:1;        /* recursion available */
  174. #endif
  175.             /* remaining bytes */
  176.     u_short    qdcount;    /* number of question entries */
  177.     u_short    ancount;    /* number of answer entries */
  178.     u_short    nscount;    /* number of authority entries */
  179.     u_short    arcount;    /* number of resource entries */
  180. } HEADER;
  181.  
  182. /*
  183.  * Defines for handling compressed domain names
  184.  */
  185. #define INDIR_MASK    0xc0
  186.  
  187. /*
  188.  * Structure for passing resource records around.
  189.  */
  190. struct rrec {
  191.     short    r_zone;            /* zone number */
  192.     short    r_class;        /* class number */
  193.     short    r_type;            /* type number */
  194.     u_long    r_ttl;            /* time to live */
  195.     int    r_size;            /* size of data area */
  196.     char    *r_data;        /* pointer to data */
  197. };
  198.  
  199. extern    u_short    _getshort();
  200. extern    u_long    _getlong();
  201.  
  202. /*
  203.  * Inline versions of get/put short/long.
  204.  * Pointer is advanced; we assume that both arguments
  205.  * are lvalues and will already be in registers.
  206.  * cp MUST be u_char *.
  207.  */
  208. #define GETSHORT(s, cp) { \
  209.     (s) = *(cp)++ << 8; \
  210.     (s) |= *(cp)++; \
  211. }
  212.  
  213. #define GETLONG(l, cp) { \
  214.     (l) = *(cp)++ << 8; \
  215.     (l) |= *(cp)++; (l) <<= 8; \
  216.     (l) |= *(cp)++; (l) <<= 8; \
  217.     (l) |= *(cp)++; \
  218. }
  219.  
  220.  
  221. #define PUTSHORT(s, cp) { \
  222.     *(cp)++ = (s) >> 8; \
  223.     *(cp)++ = (s); \
  224. }
  225.  
  226. /*
  227.  * Warning: PUTLONG destroys its first argument.
  228.  */
  229. #define PUTLONG(l, cp) { \
  230.     (cp)[3] = l; \
  231.     (cp)[2] = (l >>= 8); \
  232.     (cp)[1] = (l >>= 8); \
  233.     (cp)[0] = l >> 8; \
  234.     (cp) += sizeof(u_long); \
  235. }
  236.